<template>
    <div>
        <hd-tab :tabs="tabs"/>
        <el-form ref="form" :inline="false" :model="form" label-width="80px" size="normal">
            <el-card :body-style="{ padding: '20px' }" shadow="never">
                <div slot="header">
                    轮播管理
                </div>
                <el-form-item label="简介">
                    <el-input v-model="form.title" placeholder="简介说明"></el-input>
                    <hd-error name="title"/>
                </el-form-item>
                <el-form-item label="图片">
                    <hd-image v-model="form.url"></hd-image>
                    <hd-error name="url"/>
                </el-form-item>
                <el-form-item label="链接地址">
                    <el-input v-model="form.link" placeholder="链接地址"></el-input>
                    <hd-error name="link"/>
                </el-form-item>

                <el-button type="primary" @click="onSubmit">提交</el-button>

            </el-card>
        </el-form>

    </div>
</template>

<script>
import tabs from './tabs'

export default {
    route: false,
    props: ['id'],
    data() {
        return {
            tabs,
            form: {}
        }
    },
    async created() {
        if (this.id) this.form = await this.axios.get(`admin/slide/${this.id}`)
    },
    methods: {
        async onSubmit() {
            const url = this.id ? `admin/slide/${this.id}` : `admin/slide`
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            this.$router.push({name: 'admin.slide.index'});
        }
    }
}
</script>

<style>

</style>
